import { ImageResponse } from "next/og"; import { ENGINE_URL } from "@/lib/api"; import { PARTIES } from "@/lib/parties"; export const runtime = "nodejs"; export const alt = "QC26 — Prévision par circonscription"; export const size = { width: 1200, height: 630 }; export const contentType = "image/png"; export default async function Image({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params; let d: { name: string; regionName: string | null; forecast?: { favorite: string; p: number; parties: { party: string; voteMean: number; pWin: number }[] } } | null = null; try { d = await fetch(`${ENGINE_URL}/api/ridings/${slug}`, { next: { revalidate: 300 } }).then((r) => (r.ok ? r.json() : null)); } catch { d = null; } const color = (id: string) => PARTIES.find((p) => p.id === id)?.color ?? "#999"; const rows = (d?.forecast?.parties ?? []).filter((p) => p.party !== "aut").slice(0, 5); return new ImageResponse( (
QC26
{d?.regionName ?? "Circonscription"}
{d?.name ?? slug}
Probabilité de victoire · projection QC26
{rows.map((p) => (
{p.party.toUpperCase()}
{Math.round(p.pWin * 100)} %
))}
Élection québécoise · 5 octobre 2026qc26.ca
), { ...size }, ); }